<?php

namespace App\Http\Middleware\Api;

use Closure;

class AccessControlAllowOrigin
{
    /**
     * 允许跨域使用API
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
		/*header('Access-Control-Allow-Origin: *');
		header("Access-Control-Allow-Credentials: true");
		header("Access-Control-Allow-Methods: *");
		header("Access-Control-Allow-Headers: Content-Type,Access-Token");
		header("Access-Control-Expose-Headers: *");

        return $next($request);*/


		$response = $next($request);
		
//		$response->header('Access-Control-Allow-Origin', '*');
//		$response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Cookie, Accept');
//		$response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS');
//		$response->header('Access-Control-Allow-Credentials', 'true');
//		$response->header('Access-Control-Allow-Credentials', true);


        $response->header('Access-Control-Allow-Origin', '*');
        $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Cookie, X-CSRF-TOKEN, Accept, Authorization, X-XSRF-TOKEN');
        $response->header('Access-Control-Expose-Headers', 'Authorization, authenticated');
        $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS');
        $response->header('Access-Control-Allow-Credentials', 'true');
		return $response;
    }
}
